﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using Extensions;
using System;

namespace ConfExpert.Forms.Raporlar
{
    public partial class SiparisKesimAdet : XForm
    {
        public SiparisKesimAdet()
        {
            InitializeComponent();
        }

        private void SiparisKesimAdet_Load(object sender, EventArgs e)
        {
            
            gridView1.Init("GetSiparisKesimAdet", txtYil.EditValue.ToInt());
            gridView1.AddDetailGrid(gridView2, "CustomerId");
            gridView2.MakeColumnInvisible("CustomerId");
            gridView1.FormatAsNumber(0, "SipQty", "KesQty");
            gridView2.FormatAsNumber(0, "SipQty", "KesQty");
            gridView1.FormatAsNumber(1, "Yuzde");
            gridView2.FormatAsNumber(1, "Yuzde");
            gridView1.AddSummary("SipQty", "KesQty");
            gridView2.AddSummary("SipQty", "KesQty");
            gridView1.MakeReadOnly();
            gridView2.MakeReadOnly();

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            txtYil.EditValueChanged += txtYil_EditValueChanged;

            GridFormatRule gridFormatRule = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
            gridFormatRule.Column = gridView1.Columns["Yuzde"];
            formatConditionRuleDataBar.PredefinedName = "Yellow Gradient";
            gridFormatRule.Rule = formatConditionRuleDataBar;
            gridView1.FormatRules.Add(gridFormatRule);

            GridFormatRule gridFormatRule2 = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBar2 = new FormatConditionRuleDataBar();
            gridFormatRule2.Column = gridView2.Columns["Yuzde"];
            formatConditionRuleDataBar2.PredefinedName = "Yellow Gradient";
            gridFormatRule2.Rule = formatConditionRuleDataBar2;
            gridView2.FormatRules.Add(gridFormatRule2);

            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            //gridView2.BestFitMaxRowCount = 50;
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void txtYil_EditValueChanged(object sender, EventArgs e)
        {
            gridView1.VeriyiGuncelle(true, "GetSiparisKesimAdet", txtYil.EditValue.ToInt());
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            
        }
    }
}
